package com.unohacha.qqj.mylibrary.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

import com.unohacha.qqj.mylibrary.R;

/**
 * author: DanKeng
 * time: 23/11/2017
 */

public class LoadingDialog extends Dialog {
    private Context mContext;
    private String mMessage;
    private TextView mTvMessage;

    public LoadingDialog(Context context) {
        super(context, R.style.DialogCommon);
        mContext = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_loading);
        setCanceledOnTouchOutside(false);
//        setCancelable(false); // 返回键不可取消

        findViewById(R.id.iv_loading).startAnimation(AnimationUtils.loadAnimation(mContext, R.anim.loading));

        mTvMessage = (TextView) findViewById(R.id.tv_message);
        if (!TextUtils.isEmpty(mMessage)) {
            mTvMessage.setText(mMessage);
        }
    }

    public void setMessage(String msg) {
        mMessage = msg;
        if (mTvMessage != null) {
            mTvMessage.setText(mMessage);
        }
    }
}
